﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace UI
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //解决当时给项城部署时，端口设置的是80，后期80端口不开放的问题
            string Host = Request.Url.Host;
            string Domain = "";
            if (Host == "xinmi.qiyedaishu.com")
            {
                Domain = "xinmizhifa";
            }
            else if (Host == "dancheng.qiyedaishu.com")
            {
                Domain = "danchengizhifa";
            }
            else if (Host == "shangqiuzhifa.qiyedaishu.com")
            {
                Domain = "shangqiu";
            }
            else if (Host == "luyizhifa.qiyedaishu.com")
            {
                Domain = "luyi";
            }
            if (Domain != "")
            {
                string Method = Request.HttpMethod.ToLower();
                if (Method == "get")
                {
                    Response.Redirect("http://" + Domain + ".qiyedaishu.com:12580/Admin/Index.aspx");
                }
                else
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream))
                    {
                        WeiXin wx = new WeiXin();
                        string postParam = sr.ReadLine();
                        string result = wx.HttpPost("http://" + Domain + ".qiyedaishu.com:12580" + Request.RawUrl, postParam);
                        Response.Write(result);
                        Response.End();
                    }
                }
            }
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}